package com.souku.finance.application.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;

import com.souku.finance.application.R;
import com.souku.finance.application.utils.EdittextListenUtil;

/**
 * Created by Android on 2017/1/16.
 */

public class CalculationDialog extends Dialog implements View.OnClickListener {

    protected View rootView;
    protected EditText et1;
    protected EditText et2;
    protected EditText et3;
    protected Button btnOk;
    private boolean ishq;
    private CalculationOnClick onClick;
    private double point;

    public CalculationDialog(Context context, CalculationOnClick onClick, boolean ishq, double point) {
        super(context, R.style.myDialogFull);
        this.onClick=onClick;
        this.ishq=ishq;
        this.point=point;
    }

    public CalculationDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    protected CalculationDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_calculation);
        initView();


        if(ishq){
            btnOk.setVisibility(View.VISIBLE);
            btnOk.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClick.ok(et1,et2,et3);
                }
            });
        }else {
            btnOk.setVisibility(View.GONE);
            EdittextListenUtil.calculation(et1,et2,et3,point);
        }
    }

    @Override
    public void show() {
        super.show();
        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_ok) {

        }
    }

    private void initView() {
        et1 = (EditText) findViewById(R.id.et1);
        et2 = (EditText) findViewById(R.id.et2);
        et3 = (EditText) findViewById(R.id.et3);
        btnOk = (Button) findViewById(R.id.btn_ok);
        btnOk.setOnClickListener(CalculationDialog.this);
    }

    public interface CalculationOnClick {
        void ok(EditText et1,EditText et2,EditText et3);
    }
}
